<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Title</title>
    <script type="" language="JavaScript">
        // 或者写成 var reg = /abc/;
        var reg = new RegExp("abc");
        var str = "abdefghi";
        var b = reg.test(str);
        console.log(b);


        // 全局匹配
        var reg2 = /abc/g;
        var str2 = "abctabc"
        str2 = str2.replace(reg2, 'o');
        console.log(str2);


        // 忽略大小写
        var reg3 = /a/gi;
        var str3 = "abcAgt";
        str3 = str3.replace(reg3, '_')
        console.log(str3);

        // 结尾查找
        var reg4 = /t$/;
        var str4 = "abcAgt\nabtcgt";
        str4 = str4.replace(reg4, '_')
        console.log(str4);

        // 多行查找
        var reg5 = /t$/m;
        var str5 = "abcAgt\nabtcgt";
        str5 = str5.replace(reg5, '_')
        console.log(str5);

        // w:任意数字和字母还有下划线_
        var reg6 = /\w/gim;
        var str6 = "a_>fgeaih*#35";
        str6 = str6.replace(reg6, 'T');
        console.log(str6);


        // W:非(任意数字和字母还有下划线_)的其它字符
        var reg7 = /\W/gim;
        var str7 = "a_>fgeaih*#35";
        str7 = str7.replace(reg7, 'T');
        console.log(str7);

        // .是指除了换行符外的任意字符
        var reg8 = /./gim;
        var str8 = "a_>.fgeaih*#35";
        str8 = str8.replace(reg8, 'T');
        console.log(str8);


        // .想匹配. 需要加转义符\
        var reg9 = /\./gim;
        var str9 = "a_>.fgeaih*#35";
        str9 = str9.replace(reg9, 'T');
        console.log(str9);

        // s 空白符
        var reg10 = /\s/;
        var str10 = "\nabad\na cg";
        str10 = str10.replace(reg10, 'T');
        console.log(str10);

        // d所有数字
        var reg11 = /\d/igm;
        var str11 = "agwa54sges";
        str11 = str11.replace(reg11, 'T');
        console.log(str11);

        // \b匹配单词的开始或者结束
        var reg12 = /\b/igm;
        var str12 = "hello world";
        str12 = str12.replace(reg12, "A");
        console.log(str12);


        // ^字符的开始
        var reg13 = /^a/igm;
        var str13 = "ahello worldab";
        str13 = str13.replace(reg13, "T");
        console.log(str13);

        // $字符的结束
        var reg14 = /b$/igm;
        var str14 = "ahello worldab";
        str14 = str14.replace(reg14, "T");
        console.log(str14);

        // []
        var reg15 = /[ah]/igm;
        var str15 = "ahello worldab";
        str15 = str15.replace(reg15, "T");
        console.log(str15);

        // [^]取反
        var reg16 = /[^ah]/igm;
        var str16 = "ahello worldab";
        str16 = str16.replace(reg16, "T");
        console.log("str16: " + str16);

        // [-]表示范围
        var reg17 = /[a-z]/igm;
        var str17 = "ahello worldab";
        str17 = str17.replace(reg17, "T");
        console.log("str17: " + str17);

        // [|]表示或者
        var reg18 = /[a|z]/igm;
        var str18 = "ahelloz worldab";
        str18 = str18.replace(reg18, "T");
        console.log("str18: " + str18);

        // 出现次数
        var reg19 = /a{2}/igm;
        var str19 = "ahelloz worldaab";
        str19 = str19.replace(reg19, "T");
        console.log("str19: " + str19);

        var reg20 = new RegExp("\\w{6,16}");
        var str20 = "hsp123";
        var a20 = reg20.test(str20)
        console.log("a20: " + a20);


    </script>
</head>
<body>

</body>
</html>
<!-- 正则表达式的使用
  1.定义正则表达式的对象
  2.定义将校验的字符串
  3.校验

  -->